package sorting;

public class InsertionSorting extends Sorting{

    private int[] datas;
    
    public InsertionSorting() {
        super();
    }
    
    public InsertionSorting(int[] datas) {
        super(datas);
        this.datas = datas;
    }
    
    public void sort() {
        int outer, inner, temp;
        for (outer = 1; outer < datas.length; outer++) {
            temp = datas[outer];
            inner = outer;
            while (inner > 0 && datas[inner - 1] > temp) {
                datas[inner] = datas[inner - 1];
                --inner;
            }
            if (outer <= inner) {
                continue;
            }
            datas[inner] = temp;
        }
    }
}
